<%@ page language="java" import="java.util.*,java.sql.*"
	pageEncoding="UTF-8"%>
<html>
<head>
<title>查询信息</title>
</head>

<body>
	<%
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url1 = "jdbc:mysql://localhost:3306/user";
			String url2 = "?user=root&password=123456";
			String url3 = "&useUnicode=true&characterEncoding=UTF-8";
			String url = url1 + url2 + url3;
			Connection con = DriverManager.getConnection(url);
			request.setCharacterEncoding("UTF-8");
			String user = (String)session.getAttribute("user");
			String name = request.getParameter("name");
			
			String sql = "select * from person where name=? and user="+"'"+user+"'" + "order by id";
			PreparedStatement pstmt = con.prepareStatement(sql);
			pstmt.setString(1, name);
			
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
	%>
	<table style="margin: auto;">
		<tr>
			<td>id</td>
			<td>姓名</td>
			<td>电话</td>
		</tr>
		<tr>
			<td><%=rs.getInt("id")%></td>
			<td><%=rs.getString("name")%></td>
			<td><%=rs.getString("num")%></td>
		</tr>
	</table>
	<%
		}
		rs.last();
		if(rs.getRow()<1&&name!=null){
		out.print("查询信息不存在！");
		}
			if (rs != null)
				rs.close();
			if (pstmt != null)
				pstmt.close();
			if (con != null)
				con.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	%>
	<form action="query.jsp" method="post">
		<h3 style="text-align: center;">查询信息</h3>
		<table style="margin: auto;">
			<tr>
				<td>name</td>
				<td><input type="text" name="name">
				</td>
			</tr>
			<tr>
				<td><input type="submit" value="提交"></td>
				<td><input type="reset" value="取消"></td>
			</tr>
		</table>
	</form>
</body>
</html>
